package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.PurchaseDao;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.service.PurchaseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @Author zhmwi
 * @Date 2021/9/4
 * @Dersciption
 */
@Service
public class PurchaseServiceImpl implements PurchaseService {

    @Autowired
    private PurchaseDao purchaseDao;
    //分页查询所有库存商品
    @Override
    public PageInfo<Goods> getInventoryList(
            Integer page, Integer rows, String codeOrName, Integer goodsTypeId) {

        PageHelper.startPage(page,rows);
        List<Goods> goodsList = purchaseDao.selectInventoryList(codeOrName,goodsTypeId);
        PageInfo<Goods> pageInfo = new PageInfo<>(goodsList);

        return pageInfo;
    }

    //分页查询无库存列表展示 inventory_quantity <= 0
    @Override
    public PageInfo<Goods> getNoInventoryQuantity(Integer page, Integer rows, String nameOrCode) {
        PageHelper.startPage(page,rows);
        List<Goods> goodsList = purchaseDao.selectNoInventoryQuantity(nameOrCode);
        PageInfo<Goods> pageInfo = new PageInfo<>(goodsList);
        return pageInfo;
    }

    //分页查询有库存列表显示 >0
    @Override
    public PageInfo<Goods> getHasInventoryQuantity(Integer page, Integer rows, String nameOrCode) {
        PageHelper.startPage(page,rows);
        List<Goods> goodsList = purchaseDao.selectHasInventoryQuantity(nameOrCode);
        PageInfo<Goods> pageInfo = new PageInfo<>(goodsList);
        return pageInfo;

    }

    //补库存 修改进货价格
    @Override
    public Boolean saveStock(Integer goodsId, Integer inventoryQuantity, double purchasingPrice) {
        return purchaseDao.saveStock(goodsId,inventoryQuantity,purchasingPrice);
    }

    //查询Goods状态
    @Override
    public Integer getGoodsStateById(Integer goodsId) {
        return purchaseDao.selectGoodsStateById(goodsId);
    }

    //删除库存 其实是更新操作 逻辑删除
    @Override
    public void updateStock(Integer goodsId) {
        purchaseDao.updateStock(goodsId);
    }

    //查询库存 三表
    @Override
    public PageInfo<Goods> list(Integer page, Integer rows, String goodsName, Integer goodsTypeId) {
        PageHelper.startPage(page,rows);
        List<Goods> goodsList = purchaseDao.list(goodsName,goodsTypeId);
        PageInfo<Goods> pageInfo = new PageInfo<>(goodsList);

        return pageInfo;    }

    //查询当前库存量小于 库存下限的商品嘻嘻
    @Override
    public List<Goods> listAlarm() {
        return purchaseDao.listAlarm();
    }

    //查询所有商品 不分页
    public List<Goods> selectGoodsAll(){
        return purchaseDao.selectGoodsAll();
    }
}
